/**
 * 待确定是否此文件已废弃
 */
import React, { useState } from 'react';
import { Divider } from 'antd';
import ProForm, { ProFormText } from '@ant-design/pro-form';
import { OptType } from '@/utils/constants';
import { useModel } from 'umi';
import { getPatientList}  from '@/services/order/api';
import { showMsg } from '@/utils/utils';

interface PatientInfoProps {
  type?: string
}

const PatientInfo: React.FC<PatientInfoProps> = (props) => {
  const { type } = props;
  const { initialState } = useModel('@@initialState');
  const [patientList, setPatientList] = useState<any[]>([]);
  const [idNo, setIdNo] = useState<string>('');
  const [patientInfo, setPatientInfo] = useState<ORDERAPI.PatientInfo>({});

  // 查询患者信息
  const fetchPatientList = async (data: {
    identity_no?: string;
    ic_card_no?: string;
  }) => {
    try {
      const list = await getPatientList(data);
      setPatientList(list);
      setPatientInfo(list[0]);
    } catch (error) {
     showMsg(error?.data?.errmsg); 
    }
  }
  
  return <div className="service-record">
     <div className="header">
        <div className="title">1.患者信息</div>
      </div>
      <Divider style={{margin: '10px 0'}}/>

      <ProForm 
        submitter={{
          searchConfig: {
            submitText: '查询'
          },
          submitButtonProps: {
            disabled: type === OptType.EDIT
          },
          resetButtonProps: {
            style: {
              display: 'none'
            }
          }
        }} layout='inline'>
        <ProForm.Group>
          <ProFormText
            disabled={type === OptType.EDIT}
            name="identity_no"
            label="身份证/住院号"
            placeholder="输入完整身份证号/住院卡号"
            width={250}
            fieldProps={{
              value: idNo,
              onChange: (e: any) => {
                console.log(e);
                const value = e.target.value;
                if (value) {
                  setIdNo(value);
                  // fetchPatientList({
                  //   identity_no: value,
                  //   ic_card_no: value
                  // });
                }
              }
            }}
          />

          <ProFormText
            label="患者姓名"
            name="patient_name"
            disabled
            placeholder="输入患者姓名"
            width={200}
          />

          <ProFormText 
            label="归属科室"
            disabled
            fieldProps={{
              value: initialState?.currentUser?.dept_name
            }}
            width={200}
          />
        </ProForm.Group>
      </ProForm>
  
  </div>
}
export default PatientInfo;